﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services;
using System.Web.Script.Services;
using CoyoEden.Web.Controls;
using CoyoEden.Web.Data;
using CoyoEden.Models;
using CoyoEden.Web.Controller;
using Vivasky.Core.Infrastructure;

namespace CoyoEden.Web.Services
{
	[ScriptService]
	public class Album:WebService
	{
		#region member variables
		private ViewManager<AlbumViewBase> vm = null;
		#endregion

		#region methods
		[WebMethod]
		public FeedbackData PreEdit(Dictionary<string,string> Params) {
			Models.Album album=null;
			var id = Params["id"];
			if (!string.IsNullOrEmpty(id)) {
				album = Models.Album.GetAlbum(id);
			} else {
				album = new Models.Album(true);
			}
			vm = new ViewManager<AlbumViewBase>("~/Views/AlbumDetail.ascx");
			vm.Control.TheAlbum = album;

			FeedbackData retVal = new FeedbackData();
			retVal.IsOk = true;
			retVal.Body = vm.Render();
			return retVal;
		}
		[WebMethod]
		public FeedbackData Update(List<NameValuePair<string, string>> Params)
		{
			FeedbackData retVal = new FeedbackData();
			AlbumController.Update(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData Delete(Dictionary<string, string> Params)
		{
			FeedbackData retVal = new FeedbackData();
			AlbumController.Delete(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData SelectPics(Dictionary<string,string> Params) {
			FeedbackData retVal = null;
			AlbumController.SelectPics(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData UploadPic(Dictionary<string,string> Params) {
			FeedbackData retVal = null;
			AlbumController.UploadPic(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData SavePic(List<NameValuePair<string,string>> Params) {
			FeedbackData retVal = new FeedbackData();
			PortalFileController.Update(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData DeletePic(Dictionary<string,string> Params) {
			FeedbackData retVal = new FeedbackData();
			PortalFileController.Delete(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData ClearPics(Dictionary<string,string> Params) {
			FeedbackData retVal = new FeedbackData();
			AlbumController.ClearPics(Params, out retVal);
			return retVal;
		}
		#endregion
	}
}
